package com.codedancer.campus.manager.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.codedancer.campus.manager.service.IDynamicExamineRecordService;
import com.codedancer.campus.manager.service.vo.dynamic.DynamicExamineRecordVo;
import com.codedancer.campus.mapper.AdminMapper;
import com.codedancer.campus.mapper.DynamicExamineRecordMapper;
import com.codedancer.campus.po.Admin;
import com.codedancer.campus.po.DynamicExamineRecord;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
public class DynamicExamineRecordServiceImpl implements IDynamicExamineRecordService {

    @Autowired
    private DynamicExamineRecordMapper dynamicExamineRecordMapper;
    @Autowired
    private AdminMapper adminMapper;

    /**
     * 查询某个动态的审核记录
     *
     * @param dynamicUuid
     * @return
     */
    @Override
    public List<DynamicExamineRecordVo> list(String dynamicUuid) {
        List<DynamicExamineRecord> dynamicExamineRecords = dynamicExamineRecordMapper.list(dynamicUuid);
        return dynamicExamineRecords.stream().map(dynamicExamineRecord -> {
            DynamicExamineRecordVo dynamicExamineRecordVo = BeanUtil
                .copyProperties(dynamicExamineRecord, DynamicExamineRecordVo.class);
            Admin admin = adminMapper.selectById(dynamicExamineRecord.getExamineAdminUuid());
            dynamicExamineRecordVo.setExamineAdminName(admin.getLoginName());
            return dynamicExamineRecordVo;
        }).collect(Collectors.toList());
    }
}
